/*
 * @Author: Starfish_DL
 * @Date: 2020-11-10 14:57:36
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-10 15:17:57
 * @CurrentVersion: 1.0
 * @Description: 
 */
class Resource{
    private String name;
    private int count = 1;
    public synchronized void set(String name){
        this.name = name+count;
        count++;
        System.out.println(Thread.currentThread().getName()+"...生产者..."+this.name);
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            //done: handle exception
            System.out.println(e.getStackTrace());
        }
    }
    public void out(){
        System.out.println(Thread.currentThread().getName()+"...消费者..."+this.name);
    }
}

class MyThread01 extends Thread{
    Resource r;
    String name;
    public MyThread01(Resource r,String name) {
        super(name);
        this.r=r;
        this.name=name;
    }
    @Override
    public void run() {
        r.set(this.name);
        r.out();
    }
}

class MyThread02 extends Thread{
    Resource r;
    String name;
    public MyThread02(Resource r,String name) {
        super(name);
        this.r=r;
        this.name=name;
    }
    @Override
    public void run() {
        //r.set(this.name);
        r.out();
    }
}

public class Test01 {
    public static void main(String[] args) {
    Resource resow=new Resource();
    MyThread01 thread01=new MyThread01(resow,"th01");
    MyThread02 thread02=new MyThread02(resow,"th02");
    thread01.start();
    thread02.start();
    }
}
